<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../VueJs/vue.js"></script>
</head>

<body>
    <div id="root">
    </div>
</body>
<script>
    Vue.config.productionTip = false;

    //创建student组件
    const studentCom = Vue.extend({
        template: `
        <div>
            <h2>学生姓名:{{studentName}}</h2>
            <h2>学校年龄:{{age}}</h2>
        </div>
        `,
        data: function () {
            return {
                studentName: 'mimi',
                age: 18
            }
        }
    });

    //创建school组件
    const schoolCom = Vue.extend({
        template: `
        <div>
            <h2>学校名称:{{schoolName}}</h2>
            <h2>学校地址:{{address}}</h2>
            <student></student>
        </div>
        `,
        data: function () {
            return {
                schoolName: '尚硅谷',
                address: '北京'
            }
        },
        //局部注册组件，注册给了谁就去谁那里写标签
        components: {
            student: studentCom
        }
    });

    //创建hello组件
    const helloCom = Vue.extend({
        template: `
        <div>
            {{msg}}
        </div>`,
        data: function () {
            return {
                msg: 'hello'
            }
        }
    });

    //创建app组件
    const app = Vue.extend({
        template: `
        <div>
            <hello></hello>
            <school></school>
        </div>`,
        components: {
            school: schoolCom,
            hello: helloCom
        }
    });

    const vm = new Vue({
        el: '#root',
        template: `
            <app></app> 
        `,//这么写会将整个模板连同最外层的id="root"的那个div也被替换掉
        //局部注册组件
        components: {
            app//一人之下，万人之上
        }
    });
</script>

</html>